<template>
    <div class="app-container ">
      <el-form
        ref="form"
        label-position="left"
        size="mini"
        :model="form"
        :rules="rules"
        :inline="true"
        label-width="100px" >
        <el-tabs v-model="activeName">

            <el-row>
              <el-col :span="24">
                <el-form-item label="开启密卡" >
                  <el-switch
                    v-model="form.carmine_open"
                    active-value="1"
                    inactive-value="0"
                    active-text="开启"
                    inactive-text="关闭"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-row>
                <el-form-item label="密令长度">
                    <el-input v-model="form.length"
                    :rules="[
                    { required: true, message: '密令长度不能为空'},
                    { type: 'number', message: '密令长度必须为数字值'}
                    ]"
                    ></el-input>
                </el-form-item>
            </el-row> -->
            <el-divider />  
          </el-tab-pane>
        </el-tabs>
        <el-form-item>
          <el-button size="mini" type="primary" @click="submit">保存设置</el-button>
        </el-form-item>
      </el-form>
  
    </div>
  </template>
  <script>
  export default {
    name: 'Configpoints',
    components: {
    },
    data() {
      return {
        lang: {},
  
        loading: false,
        activeName: '',
        rules: {},
        form: {
          addcustomer: '',
          adddongtai: '',
          upjieduan: '',
          deal: '',
          status: 0
        }
      }
    },
    mounted() {
      this.$api.post('/Lang/getlang').then(res => {
        this.lang = res.data
      })
      this.$api.post('/config/getInfo', { mo: 'carmine' }).then(res => {
        this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
        this.setDefaultVal('keyword')
      })
    },
    methods: {
      submit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            this.$api.post('/config/update', this.form).then(res => {
              this.$message({ message: '操作成功', type: 'success' })
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      setDefaultVal(key) {
        if (this.form[key] == null || this.form[key] == '') {
          this.form[key] = []
        }
      }
    }
  }
  </script>
  